<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="4" :sm="6">
            <a-form-item :label=" $t('systemManagement.project') ">
              <a-select v-model="queryParam.projectCode"  v-decorator="[ 'projectCode']" :placeholder="$t('base.pleaseChoose')">
                <a-select-option v-for="item in projectList" :key="item.id" :value="item.code">
                  {{item.name}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="6">
            <a-form-item :label=" $t('base.name') ">
              <!--<a-input :placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input :placeholder="$t('base.inputVagueQuery')" v-model="queryParam.name"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <a-form-item :label=" $t('radio.radioManufacturer')">
              <j-dict-select-tag  v-model="queryParam.companyCode" :placeholder="$t('base.pleaseChoose')" dictCode="glr_yzgs"/>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <a-form-item :label=" $t('radio.radioState') ">
              <j-dict-select-tag  v-model="queryParam.status" :placeholder="$t('base.pleaseChoose')" dictCode="glr_radio_equipment_status"/>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search"> {{$t('base.query')}} </a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px"> {{$t('base.reset')}} </a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus"> {{$t('base.add')}} </a-button>

      <!--
      <div style="width: 30%;float:right;">
        音量:<a-slider id="vol_Id"  :step="5" :defaultValue="0" @afterChange="onAfterChange" />
      </div>
      -->

      <a-button type="primary" @click="batchDel" icon="delete"> {{$t('base.del')}}  </a-button>

      <a-button type="primary" @click="volSet" icon="sound"> {{$t('radio.volume')}}  </a-button>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> {{$t('base.selected')}} <a style="font-weight: 600">{{ selectedRowKeys.length }}</a> {{$t('base.item')}}
        <a style="margin-left: 24px" @click="onClearSelected"> {{$t('base.clear')}} </a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        
        @change="handleTableChange">
        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <img src="@/assets/img/zaixian.png" v-show="record.status=='Idle'"/>
            <img src="@/assets/img/lixian.png" v-show="record.status=='Offline'"/>
            <img src="@/assets/img/working.png" v-show="record.status=='Working'"/>
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)"> {{$t('base.edit')}} </a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link"> {{$t('base.more')}} <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm  :title="$t('base.confirmDelete')"  @confirm="() => handleDelete(record.id)">
                  <a> <a-icon type="delete" /> {{$t('base.del')}}  </a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <glrRadio-modal ref="modalForm" @ok="modalFormOk"></glrRadio-modal>

    <a-modal
      :title="volSetTitle"
      :visible="volSetVisible"
      :confirmLoading="volSetConfirmLoading"
      @ok="volSetHandleOk"
      @cancel="volSetHandleCancel">
      <div style="width: 100%">
        {{$t('radio.volume')}}  :<a-slider id="vol_Id" :step="1" :defaultValue="0" v-model="volValue"/>
      </div>
    </a-modal>


  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import GlrRadioModal from './modules/GlrRadioModal'
  import JInput from '@/components/jeecg/JInput'
  import { httpAction } from '@/api/manage'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'

  export default {
    name: "GlrRadioList",
    mixins:[JeecgListMixin],
    components: {
      GlrRadioModal,
      JDictSelectTag,
      JInput
    },
    data () {
      return {
        projectList:[],
        volValue:0,
        volSetVisible: false,
        volSetTitle:this.$t('radio.radioVolumeSetting') ,
        volSetConfirmLoading:false,
        description: '音柱管理管理页面',
        imagstr:null,
        sliderstatus:false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: this.$t('radio.deviceID') ,
            align:"center",
            dataIndex: 'radioId'
          },
          {
            title:this.$t('base.name'),
            align:"center",
            dataIndex: 'name'
          },
          {
            title:this.$t('radio.materialCode') ,
            align:"center",
            dataIndex: 'materialCode'
          },
          {
            title: this.$t('base.status') ,
            align:"center",
            scopedSlots: {customRender: "avatarslot"}
          },
          {
            title:this.$t('radio.volume') ,
            align:"center",
            dataIndex: 'vol'
          },
          {
            title: this.$t('radio.radioManufacturer') ,
            align:"center",
            dataIndex: 'companyCode_dictText'
          },
          {
            title: this.$t('radio.belongingType') ,
            align:"center",
            dataIndex: 'terminalType_dictText'
          },
          {
            title: this.$t('radio.installDate') ,
            align:"center",
            dataIndex: 'installDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title: this.$t('base.operation'),
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/glr/glrRadio/list",
          delete: "/glr/glrRadio/delete",
          deleteBatch: "/glr/glrRadio/deleteBatch",
          exportXlsUrl: "/glr/glrRadio/exportXls",
          importExcelUrl: "glr/glrRadio/importExcel",
          setRadioVol: "glr/glrRadio/setRadioVol",
          getProjectList: "/glr/glrProject/getProject",
        },
        dictOptions:{
        },
      }
    },
    created(){
      const that = this;
      httpAction(that.url.getProjectList,{},"post").then((res)=>{
        if(res.success){
          that.projectList=res.result;
        }else{
          //that.$message.warning(res.message);
          that.$message.warning(that.$t('base.operationFailed'));
        }
      }).finally(() => {
        that.confirmLoading = false;
      })
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }

    },
    methods: {
      initDictConfig(){
      },
      volSet: function(){
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning(this.$t('base.pleaseSelectARecord'));
          return;
        }else{
          this.volValue=0;
          this.volSetVisible=true;
        }
      },
      volSetHandleCancel:function(){
        this.volSetClose()
      },
      volSetClose () {
        this.volSetVisible = false;
      },
      volSetHandleOk:function(){
        var ids = "";
        var that = this;
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning(this.$t('base.pleaseSelectARecord'));
          return;
        } else {
          that.sliderstatus=true;
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          if(!that.sliderstatus){
            return;
          }
          that.loading = true;
          httpAction(that.url.setRadioVol, {ids: ids,vol:that.volValue},"post").then((res) => {
            if (res.success) {
              debugger
              that.loadData();
              that.onClearSelected();
              that.volSetClose();
              //that.$message.success(res.message);
              that.$message.success(that.$t('base.operationSuccessful'));

            } else {
              //that.$message.warning(res.message);
              that.$message.warning(that.$t('base.operationFailed'));
            }
          }).finally(() => {
            that.sliderstatus=false;
            that.loading = false;
          });
        }
      },
       
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>